home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / vgamaze4.zip / VGA3D.CPP < prev    next >
C/C++ Source or Header  |  1994-03-02  |  2KB  |  90 lines

  1. #include <iostream.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <graphics.h>
  6. #include <stdlib.h>
  7. #include "titillat.h"
  8. #include "plot3d.h"
  9. #include "vga3d.h"
  10.  
  11. #ifndef TRUE
  12. #define TRUE -1
  13. #endif
  14. #ifndef FALSE
  15. #define FALSE 0
  16. #endif
  17.  
  18. vga3d::vga3d()
  19.   {
  20.     registerbgidriver(EGAVGA_driver);
  21.       // See the Borland documentation on the utilities "BINOBJ" and "TLIB"
  22.       // for information on how to link "EGAVGA.BGI" into a program from
  23.       // "GRAPHICS.LIB".
  24.     AspectRatio=(HEIGHT_OF_SCREEN/WIDTH_OF_SCREEN)
  25.      /(((double) NUM_Y_PIXELS)/((double) NUM_X_PIXELS));
  26.     graph_open=FALSE;
  27.   }
  28.  
  29. vga3d::~vga3d()
  30.   {
  31.     if (graph_open)
  32.       closegraph();
  33.   }
  34.  
  35. int vga3d::display_initialized()
  36. // Set display to 640x480x16 VGA mode.  Define shades of gray and color for 
  37. // highlighting.
  38.     {
  39.       int                errorcode;
  40.       int                graphdriver;
  41.       int                graphmode;
  42.       struct palettetype palette;
  43.       int                tint;
  44.  
  45.       if (graph_open)
  46.         {
  47.           closegraph();
  48.           graph_open=FALSE;
  49.         }
  50.       graphdriver=VGA;
  51.       graphmode=VGAHI;
  52.       initgraph((int far *) &graphdriver,(int far *) &graphmode,"");
  53.       if ((errorcode=graphresult()) == grOk)
  54.         {
  55.           graph_open=TRUE;
  56.           getpalette(&palette);
  57.           // Only 16 "colors" are allowed in this graphics mode.
  58.           for (int color_num=0; color_num < 15; color_num++)
  59.           // Get 15 evenly spaced shades of gray.
  60.             {
  61.               tint=(63*color_num)/14;
  62.               tint&=0xfc;
  63.               setrgbpalette(palette.colors[color_num],tint,tint,tint);
  64.             }
  65.           // Set the highlighting color to red.
  66.           setrgbpalette(palette.colors[15],0xfc,0,0);
  67.         }
  68.       else
  69.         {
  70.           closegraph();
  71.           cerr << "Fatal error: " << grapherrormsg(errorcode) << '\n';
  72.         }
  73.       return graph_open;
  74.     }
  75.  
  76. void vga3d::pset(
  77.   int x,
  78.   int y,
  79.   int color_num)
  80.     {
  81.       if (color_num <= NUM_COLORS)
  82.         {
  83.           if (color_num == NUM_COLORS) // highlighted
  84.             putpixel(x,y,15);
  85.           else                         // gray
  86.             putpixel(x,y,(14*color_num)/(NUM_COLORS-1));
  87.         }
  88.       return;
  89.     }
  90.